﻿using IBLL;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MODEL;

namespace API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class OrgaController : ControllerBase
    {
        public OrgaController(IOrganizationBLL bll,ILogger<OrgaController> logger)
        {
            Bll = bll;
            Logger = logger;
        }

        public IOrganizationBLL Bll { get; }
        public ILogger<OrgaController> Logger { get; }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="organization">机构信息对象</param>
        /// <returns>受影响行数</returns>
        [HttpPost]
        public async Task<int> AddOrgan(Organization organization)
        {
            try
            {
                Logger.LogInformation("执行添加功能");
                return await Bll.AddOrgan(organization);
            }
            catch (Exception)
            {
                Logger.LogError("出现异常，抛出");
                throw;
            }
        }
        /// <summary>
        /// 查询+分页
        /// </summary>
        /// <param name="name">机构名称</param>
        /// <param name="sid">服务类型</param>
        /// <param name="pageindex">页码</param>
        /// <param name="pagesize">页容量</param>
        /// <returns>返回匿名类</returns>
        [HttpGet]
        public dynamic GetList(string? name, int sid, int pageindex, int pagesize)
        {
            try
            {
                Logger.LogInformation("执行查询功能");
                return Bll.GetList(name, sid, pageindex, pagesize);
            }
            catch (Exception)
            {
                Logger.LogError("出现异常，抛出");
                throw;
            }
        }
        /// <summary>
        /// 数据绑定服务
        /// </summary>
        /// <returns>返回服务表集合</returns>
        [HttpGet]
        public List<Service> GetServices()
        {
            try
            {
                Logger.LogInformation("获取服务表信息");
                return Bll.GetServices();
            }
            catch (Exception)
            {
                Logger.LogError("出现异常，抛出");
                throw;
            }
        }
        /// <summary>
        /// 批量删除（逻辑）
        /// </summary>
        /// <param name="idstring">字符串数组</param>
        /// <returns>受影响行数</returns>
        [HttpDelete]
        public async Task<int> RangeDelete(string idstring)
        {
            try
            {
                Logger.LogInformation("执行批量删除功能");
                return await Bll.RangeDelete(idstring);
            }
            catch (Exception)
            {
                Logger.LogError("出现异常，抛出");
                throw;
            }
        }
        /// <summary>
        /// 批量修改状态
        /// </summary>
        /// <param name="idstring">字符串数组</param>
        /// <returns>受影响行数</returns>
        [HttpGet]
        public async Task<int> UpdateStutus(string idstring)
        {
            try
            {
                Logger.LogInformation("执行批量修改状态功能");
                return await Bll.UpdateStutus(idstring);

            }
            catch (Exception)
            {
                Logger.LogError("出现异常，抛出");
                throw;
            }
        }
    }
}
